package com.gskj.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gskj.eduservice.entity.EduTeacher;
import com.gskj.eduservice.mapper.EduTeacherMapper;
import com.gskj.eduservice.service.IEduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-05-13
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements IEduTeacherService {

    @Override
    public Map<String, Object> getTeacherFrontPageList(Page<EduTeacher> eduTeacherPage) {

        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();

        wrapper.orderByDesc("sort"); // 降序排序
        // 分页查询
        baseMapper.selectPage(eduTeacherPage, wrapper);

        long total = eduTeacherPage.getTotal(); // 总记录数
        List<EduTeacher> records =
                eduTeacherPage.getRecords(); // 集合
        long current = eduTeacherPage.getCurrent(); // 当前页码
        long pages = eduTeacherPage.getPages(); // 总页码

        boolean hasNext = eduTeacherPage.hasNext(); // 是否有下一页
        boolean hasPrevious = eduTeacherPage.hasPrevious(); // 是否有上一页

        //将分页中的数据放入 map
        Map<String, Object> map = new HashMap<>();
        map.put("total", total);
        map.put("items", records);
        map.put("current", current);
        map.put("pages", pages);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return map;
    }
}
